package com.css.fxfzxczh.modules.buildingKilometerGrid.repository;

import com.css.fxfzxczh.modules.buildingKilometerGrid.model.entity.FxqhBuildingGridFieldDesc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 建筑物公里网格字段说明repository
 */
@Repository
public class FxqhBuildingGridFieldDescRepository {
    @Autowired
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 插入
     *
     * @param fxqhBuildingGridFieldDesc
     */
    public void insert(FxqhBuildingGridFieldDesc fxqhBuildingGridFieldDesc) {
        SqlParameterSource source = new BeanPropertySqlParameterSource(fxqhBuildingGridFieldDesc);
        String sql = "INSERT INTO fxqh_building_grid_field_desc(id, data_name, data_type, is_must, data_desc, sort, build_grid_type) values(:id, :dataName, :dataType, :isMust, :dataDesc , :sort, :buildGridType)";
        namedParameterJdbcTemplate.update(sql, source);
    }

    public List<FxqhBuildingGridFieldDesc> listByBuildGridType(String dataType) {
        return jdbcTemplate.query("select * from fxqh_building_grid_field_desc where build_grid_type = '" + dataType + "' order by sort asc ", new BeanPropertyRowMapper<>(FxqhBuildingGridFieldDesc.class));
    }
}
